//
//  BanBu_MyAccountViewController.m
//  BanBu
//
//  Created by banbu3 on 13-12-2.
//
//

#import "BanBu_MyAccountViewController.h"
#import "AppDataManager.h"
#import "BanBu_NavButton.h"
@interface BanBu_MyAccountViewController ()
{
    UIWebView *_webView;
}
@end

@implementation BanBu_MyAccountViewController

-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:animated];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height-44)];
    _webView.scrollView.bounces = NO;
    NSURLRequest *request = nil;
    NSLog(@"%@",MyAppDataManager.banbuHostIP);
    NSString *urlStr = [NSString stringWithFormat:@"%@/_user_login/_get_my_score_account.php?lang=%@&loginid=%@",MyAppDataManager.banbuHostIP,[MyAppDataManager getLanguageSubmitToServer],MyAppDataManager.loginid];
    NSLog(@"%@",urlStr);
        request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
        
    [_webView loadRequest:request];
    
    _webView.delegate = self;
    
    [self.view addSubview:_webView];
    [_webView release];
    self.title  = NSLocalizedString(@"myAccount", nil);
    [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];
//    BanBu_NavButton *chargeBtn = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
//    chargeBtn.position = ButtonPositionRight;
//    
//    [chargeBtn addTarget:self action:@selector(charge) forControlEvents:UIControlEventTouchUpInside];
//    chargeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//
//    [chargeBtn setTitle:NSLocalizedString(@"recharge", nil) forState:UIControlStateNormal];
//    CGFloat w = [NSLocalizedString(@"recharge", nil) sizeWithFont:[UIFont systemFontOfSize:14] forWidth:100 lineBreakMode:NSLineBreakByWordWrapping].width+10;
//    chargeBtn.frame=CGRectMake(0, 0,w, 30);
//    UIBarButtonItem *cancelItem = [[[UIBarButtonItem alloc] initWithCustomView:chargeBtn] autorelease];
//    self.navigationItem.rightBarButtonItem = cancelItem;
//    [chargeBtn release];
    
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSURL *requestURL =[ [ request URL ] retain ];
    if(navigationType == UIWebViewNavigationTypeLinkClicked){
        if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ])) {
            return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
        }
    }
    [ requestURL release ];
    return YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
       [TKLoadingView dismissTkFromView:self.view animated:NO afterShow:0];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [TKLoadingView dismissTkFromView:self.view animated:NO afterShow:0];
    [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:1];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
